home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / ispell-3.1.18src / amiga.c next >
C/C++ Source or Header  |  1998-08-27  |  8KB  |  321 lines

  1. static char RCS_Amiga_ID[]=
  2.   "$Id: amiga.c 1.7 1998/08/25 14:31:14 jskov-eburghar Exp $";
  3.  
  4. /*
  5.  * $Log: amiga.c $
  6.  * Revision 1.7  1998/08/25  14:28:20  eburghar
  7.  * CHECK and QUICKCHECK now use strtoichar() instead of the own written routine
  8.  * Now they handle accentuated words correctly (french dictionary)
  9.  *
  10.  * Revision 1.6  1995/09/21  15:39:06  jskov
  11.  * Now compiles with includes 3.1
  12.  *
  13.  * Revision 1.5  1995/07/03  23:54:58  jskov
  14.  * Removed #include "version.h" - version strings are now in an object
  15.  *
  16.  * Revision 1.4  1995/06/30  13:13:00  jskov
  17.  * RCS version string is now in the object code for easy id of patch revision
  18.  *
  19.  * Revision 1.3  1995/06/30  12:40:21  jskov
  20.  * Added initialization of ctoken
  21.  *
  22.  * Revision 1.2  1995/06/30  10:10:16  jskov
  23.  * Added "ACCEPT" command - accepts word for the rest of the session.
  24.  *
  25.  * Revision 1.1  1995/06/30  00:03:56  jskov
  26.  * Initial revision
  27.  *
  28.  */
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include "config.h"
  33. #include "ispell.h"
  34. #include "proto.h"
  35. #include "msgs.h"
  36. #include <dos/dos.h>
  37.  
  38. extern char * Version_ID[];
  39.  
  40. void rexxaccept (struct RexxMsg *msg, char *inword);
  41.  
  42. struct rexxCommandList rcl[] =
  43. {
  44.   {"add", &rexxadd},
  45.   {"quickadd", &rexxquickadd},
  46.   {"accept", &rexxaccept},
  47.   {"check", &rexxcheck},
  48.   {"quickcheck", &rexxquickcheck},
  49.   {"lookup", &rexxlookup},
  50.   {"filecheck", &rexxfilecheck},
  51.   {"version", &rexxversion},
  52.   {"exit", &rexxexit},
  53.   {NULL, NULL}
  54. };
  55.  
  56. SHORT KeepGoing = TRUE; /* main loop control value */
  57.  
  58. char rootword[BUFSIZ];
  59.  
  60. int wflag = 0;
  61.  
  62. struct RexxMsg *RexxMsg;
  63.  
  64. void servermode()
  65. {
  66.   long rexxbit;
  67.   long returnbits;
  68.  
  69.   rexxbit = upRexxPort ("IRexxSpell", rcl, NULL, &disp);
  70.  
  71.   printf("Entered ARexx server mode!\n");
  72.   printf("Pass commands through port 'IRexxSpell'\n");
  73.   fflush (stdout);
  74.  
  75.   while (KeepGoing)
  76.     {
  77.       returnbits = Wait (rexxbit | SIGBREAKF_CTRL_C);
  78.       if (returnbits & SIGBREAKF_CTRL_C)
  79.         KeepGoing = 0;
  80.       if (returnbits & rexxbit)
  81.         dispRexxPort ();
  82.     }
  83. /*
  84.  *   With Rexx, we need to bring the port down.  You might make this
  85.  *   part of exit() for programs that have multiple paths to exit.
  86.  */
  87.   dnRexxPort ();
  88. }
  89.  
  90.  
  91. /*
  92.  *   Now we get into the actual code necessary for our REXX port; functions
  93.  *   that do the real work.  Note that this program was not structured
  94.  *   particularly nicely for Rexx; I had to write each of these functions.
  95.  *   Many programs have these subroutines already in place; they are called
  96.  *   as part of the event loop.  This progam, however, just has one big
  97.  *   switch statement with different actions . . .
  98.  *
  99.  *   First, our locals.
  100.  */
  101. /*
  102.  *   This is our main dispatch function.
  103.  */
  104. void disp (struct RexxMsg *msg, struct rexxCommandList *dat, char *p)
  105. {
  106.   (*(dat->userdata)) (msg, p);
  107. }
  108.  
  109. /*
  110.  *   This handler adds a word to the `global personal dictionary.'
  111.  *
  112.  *   Now, in English, the word is added to whatever personal
  113.  *   dictionary was found when ISpell was started up in ARexx
  114.  *   server mode. (Under a multiuser system, we might want to
  115.  *   restrict who can add words to this dictionary.  For now
  116.  *   we just do it!  Yes, the AmigaOS is multiuser, hehe :-).
  117.  *   No protection, the way true hackers like it, you (the 
  118.  *   user) get more rope to hang yourself :-), err the system 
  119.  *   with :-).
  120.  */
  121. void rexxadd (struct RexxMsg *msg, char *inword)
  122. {
  123.   if (*inword)
  124.     treeinsert (ichartosstr (strtosichar (inword, 0), 1), ICHARTOSSTR_SIZE, 1);
  125.   treeoutput ();
  126.   replyRexxCmd (msg, 0L, 0L, "ok");
  127. }
  128.  
  129. /*
  130.  *   The quick version does not write the changes to disk.
  131.  *   Useful if you will be adding many words.  Be sure to
  132.  *   call rexxadd at the end of the list (pass a null word,
  133.  *   or a valid new word to be added).
  134.  */
  135. void rexxquickadd (struct RexxMsg *msg, char *inword)
  136. {
  137.   if (*inword)
  138.     treeinsert (ichartosstr (strtosichar (inword, 0), 1), ICHARTOSSTR_SIZE, 1);
  139.   replyRexxCmd (msg, 0L, 0L, "ok");
  140. }
  141.  
  142. /*
  143.  * Accept word for the rest of this session. Obviously there is no need
  144.  * for saving the tree.
  145.  */
  146.  
  147. void rexxaccept (struct RexxMsg *msg, char *inword)
  148. {
  149.   if (*inword)
  150.     treeinsert (ichartosstr (strtosichar (inword, 0), 1), ICHARTOSSTR_SIZE, 0);
  151.   replyRexxCmd (msg, 0L, 0L, "ok");
  152. }
  153.  
  154. /*
  155.  *   This handler checks the spelling of a word.
  156.  */
  157.  
  158. void rexxcheck (struct RexxMsg *msg, char *inword)
  159. {
  160.   char buf[512];
  161.   char aWord[INPUTWORDLEN + MAXAFFIXLEN];
  162.   int i;
  163.  
  164.   if (strtoichar (itoken, inword, INPUTWORDLEN * sizeof (ichar_t), 0))
  165.       (void) fprintf (stderr, WORD_TOO_LONG (ctoken));
  166.  
  167.   currentchar = inword;                                         /* Global ISpell vars */
  168.  
  169.   if (good (itoken, 0, 0, 0, 0)){
  170.         if (hits[0].prefix == NULL && hits[0].suffix == NULL){
  171.           /* perfect match */
  172.           strcpy (buf, "*");
  173.         } else {
  174.           /* matched because of root */
  175.           sprintf (buf, "+ %s", hits[0].dictent->word);
  176.         }
  177.   } else if (compoundgood (itoken, 0)){
  178.         /* compound-word match */
  179.         strcpy (buf, "-");
  180.   }     else {
  181.         makepossibilities (itoken);
  182.         if (pcount){
  183.           /*
  184.           ** print &  or ?, ctoken, then
  185.           ** character offset, possibility
  186.           ** count, and the possibilities.
  187.           */
  188.           sprintf (buf, "%c %s %d", easypossibilities ? '&' : '?',ctoken, easypossibilities);
  189.           for (i = 0;  i < MAXPOSSIBLE;  i++){
  190.                 if (possibilities[i][0] == 0)
  191.                   break;
  192.                 sprintf (aWord, "%c %s",i ? ',' : ':', possibilities[i]);
  193.           strcat(buf, aWord);
  194.           }
  195.         } else {
  196.           /*
  197.           ** No possibilities found for word TOKEN
  198.           */
  199.           (void) sprintf (buf, "# %s", ctoken);
  200.         }
  201.   }
  202.   replyRexxCmd (msg, 0L, 0L, buf);
  203. }
  204.  
  205.  
  206. /*
  207.  *   This handler checks the spelling of a word, it does
  208.  *   not try to find replacement words as above.  It only
  209.  *   determines whether or not the word is in the dictoinary.
  210.  */
  211. void rexxquickcheck (struct RexxMsg *msg, char *inword)
  212. {
  213.  
  214.   if (strtoichar (itoken, inword, INPUTWORDLEN * sizeof (ichar_t), 0))
  215.       (void) fprintf (stderr, WORD_TOO_LONG (ctoken));
  216.  
  217.   currentchar = inword;                                         /* Global ISpell vars */
  218.  
  219.   if (good (itoken, 0, 0, 0, 0) || compoundgood(itoken, 0))
  220.     replyRexxCmd (msg, 0L, 0L, "ok");
  221.   else
  222.     replyRexxCmd (msg, 0L, 0L, "bad");
  223. }
  224.  
  225. /*
  226.  * Find words matching a regular expression
  227.  */
  228. void rexxlookup (struct RexxMsg *msg, char *p)
  229. {
  230.   char buf[512];
  231.   char cmd[512];
  232.   char *rval;
  233.   int whence = 0;
  234.   int bufend = 1;
  235.   int lookupsize;
  236.  
  237.   strcpy (buf, "&");
  238.   sprintf (cmd, "^%s$", p);
  239.   while ((rval = do_regex_lookup (cmd, whence)) != NULL){
  240.         whence=1;
  241.         lookupsize = strlen(rval);
  242.         if ((lookupsize + bufend) > 511)
  243.           break;
  244.         strcpy (&(buf[bufend++]), " ");
  245.         strcpy (&(buf[bufend]), rval);
  246.         bufend += lookupsize;
  247.   }
  248.   replyRexxCmd (msg, 0L, 0L, buf);
  249. }
  250.  
  251. /*
  252.  *   This handler checks the spelling of a file.
  253.  */
  254. void rexxfilecheck (struct RexxMsg *msg, char *p)
  255. {
  256.   char *cp;
  257.  
  258.   currentfile = p;
  259.  
  260.   if ((infile = fopen (p, "r")) == NULL){
  261.         replyRexxCmd (msg, 0L, 0L, "Error: Can't open input file");
  262.         return;
  263.   }
  264.  
  265.   tmpnam (tempfile);
  266.  
  267.   if ((outfile = fopen (tempfile, "w")) == NULL){
  268.         replyRexxCmd (msg, 0L, 0L, "Error: Can't open output file");
  269.         return;
  270.   }
  271.  
  272.   quit = 0;
  273.  
  274.   /* See if the file is a .tex file.  If so, set the appropriate flag. */
  275.   if ((cp = (char *) strrchr (p, '.')) != NULL && strcmp (cp, ".tex") == 0)
  276.     tflag = 1;
  277.   else
  278.     tflag = 0;
  279.  
  280.   lflag = 1;
  281.  
  282.   checkfile ();
  283.  
  284.   fclose (infile);
  285.   fclose (outfile);
  286.  
  287.   replyRexxCmd (msg, 0L, 0L, tempfile);
  288. }
  289.  
  290. /*
  291.  *   This handler returns the version of the program.
  292.  */
  293. void rexxversion (struct RexxMsg *msg, char *p)
  294. {
  295.   char buf[512];
  296.   int bufend;
  297.   int namesize;
  298.   int i;
  299.  
  300.   sprintf(buf, "%s\n%s\n", Version_ID[0], Version_ID[2]);
  301.   bufend=strlen(buf);
  302.   for (i = 0; rcl[i].name != NULL; i++){
  303.         namesize = strlen(rcl[i].name);
  304.         if ((namesize + bufend) > 511)
  305.           break;
  306.         bufend=+namesize+1;
  307.         strcat (buf, " ");
  308.         strcat (buf, rcl[i].name);
  309.   }
  310.   replyRexxCmd (msg, 0L, 0L, buf);
  311. }
  312.  
  313. /*
  314.  *   This handler sets the exit flag.
  315.  */
  316. void rexxexit (struct RexxMsg *msg, char *p)
  317. {
  318.   KeepGoing = 0;
  319.   replyRexxCmd (msg, 0L, 0L, "bye");
  320. }
  321.